import Vue from 'vue'
import VueRouter from 'vue-router'
import {getItem} from "@/utils/auth";


Vue.use(VueRouter)

const routesMb = [
    // {path: '/', name: 'home', component: () => import('../views/homePage/upload.vue')},
    // {path: '/mine', name: 'mine', component: () => import('../views/pageMine/upload.vue')},
    // {path: '/login', name: 'login', component: () => import('../views/pageLogin/upload.vue')},
    // {path: '/reg', name: 'reg', component: () => import('../views/pageReg/upload.vue')},
    // {path: '/list', name: 'list', component: () => import('../views/pageList/upload.vue')},
    // {path: '/news', name: 'news', component: () => import('../views/pageNews/upload.vue')},
    // {path: '/recharge', name: 'recharge', component: () => import('../views/recharge/upload.vue')},
    // {path: '/withdraw', name: 'withdraw', component: () => import('../views/withdraw/upload.vue')},
    // {path: '/wallet', name: 'wallet', component: () => import('../views/wallet/upload.vue')},
    // {path: '/buyRecord', name: 'buyRecord', component: () => import('../views/buyingRecords/upload.vue')},
    // {path: '/fundDetail', name: 'fundDetail', component: () => import('../views/fundDetails/upload.vue')},
    // {path: '/complain', name: 'complain', component: () => import('../views/complaintFeedback/upload.vue')},
    // {path: '/message', name: 'message', component: () => import('../views/message/upload.vue')},
    // {path: '/security', name: 'security', component: () => import('../views/pageAccountSecurity/upload.vue')},
    // {path: '/realName', name: 'realName', component: () => import('../views/pageRealName/upload.vue')},
    // {path: '/newsDetail', name: 'newsDetail', component: () => import('../views/pageNewsDetail/upload.vue')},
    // {path: '/shares', name: 'shares', component: () => import('../views/pageShares/upload.vue')},
    // {path: '*', name: 'activity', component: () => import('../views/notPage/upload.vue')},
]
const routesPc = [
    {path: '/login', name: 'login',meta: {active: null,keepAlive:false}, component: () => import('../page/pageLogin/index.vue')},
    {path: '/', name: 'home',meta: {active: 1,keepAlive:false}, component: () => import('../page/pageHome/index.vue')},
    {path: '/tender', name: 'tender',meta: {active: 2,keepAlive:false}, component: () => import('../page/pageTender/index.vue')},
    {path: '/zt', name: 'zt',meta: {active: 2,keepAlive:false}, component: () => import('../page/pageZt/index.vue')},
    {path: '/upload', name: 'upload',meta: {active: 4,keepAlive:false}, component: () => import('../page/pageUploads/index.vue')},
    {path: '/customized', name: 'customized',meta: {active: 3,keepAlive:false}, component: () => import('../page/pageCustomized/index.vue')},
    {
        path: '/user',
        name: 'user',
        meta: {active: null,keepAlive:false},
        component: () => import('../page/pageUser/index.vue'),
        children:[
            {
                path: 'home',
                name: 'home',
                meta:{checked:1,keepAlive:false},
                component: () => import( '../page/pageUser/components/Home.vue')
            },
            {
                path: 'invoice',
                name: 'invoice',
                meta:{checked:2,keepAlive:false},
                component: () => import( '../page/pageUser/components/Invoice.vue')
            },
            {
                path: 'collect',
                name: 'collect',
                meta:{checked:3,keepAlive:false},
                component: () => import( '../page/pageUser/components/collect.vue')
            },
            {
                path: 'download',
                name: 'download',
                meta:{checked:4,keepAlive:false},
                component: () => import( '../page/pageUser/components/download.vue')
            },
            {
                path: 'buy',
                name: 'buy',
                meta:{checked:5,keepAlive:false},
                component: () => import( '../page/pageUser/components/buyRecord.vue')
            },
            {
                path: 'upload',
                name: 'upload',
                meta:{checked:6,keepAlive:false},
                component: () => import( '../page/pageUser/components/upload.vue')
            },
            {
                path: 'account',
                name: 'account',
                meta:{checked:7,keepAlive:false},
                component: () => import( '../page/pageUser/components/account.vue')
            },
        ],


    },
]

var routes=[]
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
    routes = routesMb
} else {
    routes = routesPc
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior: () => ({ y: 0 }),//每次都跳转到顶部
})

// router.beforeEach((to, from, next) => {
//     // 读取数据
//     let token = getItem('admin');
//     let user = getItem('BaseUser')
//     if(token && user){
//         next();
//     }else{
//         let reg = RegExp('reg|pc|login|50x|')
//         if (reg.test(to.path)){
//             next()
//         } else{
//            router.replace('/login')
//         }
//     }
// })
export default router
